#include "client.h"

void init_client (sendMessage_t * message) {
  int create_socket;
  char *buffer = malloc (BUF);
  struct sockaddr_in address;
  int size;

  if ((create_socket = socket (AF_INET, SOCK_STREAM, 0)) > 0)
    printf ("(CLIENT) Socket wurde angelegt\n");

  address.sin_family = AF_INET;
  address.sin_port = htons (15000);
  inet_aton (message->ip, &address.sin_addr);

  if (connect ( create_socket,
                (struct sockaddr *) &address,
                sizeof (address)) == 0)
    printf ("(CLIENT) Verbindung mit dem Server (%s) hergestellt\n",
       inet_ntoa (address.sin_addr));
  //do {
      //size = recv(create_socket, buffer, BUF-1, 0);
      //if( size > 0)
      //   buffer[size] = '\0';
      //printf ("(CLIENT) Nachricht erhalten: %s\n", buffer);
      //if (strcmp (buffer, "quit\n")) {
         //printf ("(CLIENT) Nachricht zum Versenden: ");
         //fgets (buffer, BUF, stdin);
  		
  		printf("(CLIENT) %s\n", (char *)message->message);
        send(create_socket, message->message, strlen (message->message), 0);
      // }
  //} while (strcmp (buffer, "quit\n") != 0);
  close (create_socket);
}
